using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using Garbe.Sound;
namespace etbTOEIC
{
	/// <summary>
	/// Summary description for DB2MainForm.
	/// </summary>
	public class DB2MainForm
	{
		static public long TestID = 0;
		static public string ExamCode = "Untitle";
		static public string stCurrentUser = "";
		//Exam info
		static public string stSchool = "", stClass = "", stNotes = "";
		static public long Duration = 0;
		static public DateTime dtCreate = DateTime.Today;
		static public DateTime dtLastUpdate = DateTime.Today;
		//report info
		static public string stPageDirection = "Go on to the next page";
		static public string stReportHeader = "NONG LAM UNIVERSITY \r\n FOREIGN LANGUAGE CENTER";
		static public string stReportFooter = " THIS IS THE END OF YOUR TEST";
		static public bool isDisplayPageNumber = true, isDisplaySchool = true, isDisplayClass = true, isDisplayExamCode = true;
		// Hash Table
		static public Hashtable htID2TreeNode = new Hashtable ();
		public DB2MainForm()
		{
			//
			// TODO: Add constructor logic here
			//
		}

		
		#region /* Load du lieu tu DB ==> QuestionTreeView */
		static public void LoadDB2Tree(TreeView trv)
		{
			trv.Nodes.Clear();
			DataSet myDataSet = new DataSet();
			MyDatabase.GetSections(0, ref myDataSet);
			foreach(DataTable myTable in myDataSet.Tables)
			{
				foreach(DataRow myRow in myTable.Rows)
				{
					TreeNode nodeNew = new TreeNode(myRow["Title"].ToString());
					nodeNew.Tag = "S" + myRow["SectionID"].ToString();
					htID2TreeNode[nodeNew.Tag] = nodeNew;
					
					trv.Nodes.Add(nodeNew);
					
					LoadListTopics(nodeNew, Convert.ToInt64(myRow["SectionID"].ToString()), true);
				}
			}
		}
		static public void LoadListTopics(TreeNode node, long SectionId, bool isFullLoad)
		{
			node.Nodes.Clear();
			DataSet myDataSet = new DataSet();
			MyDatabase.GetTopics(SectionId, 0, ref myDataSet);
			foreach(DataTable myTable in myDataSet.Tables)
			{
				foreach(DataRow myRow in myTable.Rows)
				{
					string sTFieldTitle = "Title";
					if (SectionId==4)	sTFieldTitle = "Passages";
					string stTittle = myRow[sTFieldTitle].ToString();
					int index = stTittle.IndexOf("#");
					if(index != -1)
						stTittle = stTittle.Substring(0, index);
					TreeNode nodeNew = new TreeNode(stTittle);
					nodeNew.Tag = "T" + myRow["TopicID"].ToString();
					htID2TreeNode[nodeNew.Tag] = nodeNew;
					
					node.Nodes.Add(nodeNew);
			
					LoadListQuestions(nodeNew, SectionId, Convert.ToInt64(myRow["TopicID"].ToString()), true);
				}
			}
		}
		static public void LoadListQuestions(TreeNode node, long SectionId, long TopicId, bool isFullLoad)
		{
			node.Nodes.Clear();
			DataSet myDataSet = new DataSet();
			MyDatabase.GetQuestions(TopicId, 0, ref myDataSet);
			foreach(DataTable myTable in myDataSet.Tables)
			{
				foreach(DataRow myRow in myTable.Rows)
				{
					TreeNode nodeNew = new TreeNode(GetQuestionText(myRow));
                    nodeNew.Tag = "Q" + myRow["QuestionID"].ToString();
					if(SectionId == 6)
					{
						string stTemp = nodeNew.Text;
						int index = stTemp.IndexOf("<br>");
						if(index > -1)
							stTemp = stTemp.Substring(0, index);
						stTemp = stTemp.Replace("&nbsp;", " ");
						stTemp = stTemp.Replace("<U>", "");
						stTemp = stTemp.Replace("</U>", "");
						nodeNew.Text = stTemp;
					}
					htID2TreeNode[nodeNew.Tag] = nodeNew;
					
					node.Nodes.Add(nodeNew);
				}
			}
		}
		#endregion

		#region /* Cac thao tac tren Topic : LOAD, ADD, UPDATE, DEL */
		static public void LoadTopic(long SectionID, long TopicID, ref TextBox txtTitle,ref TextBox txtPassages,ref  TextBox txtTape, ref TextBox txtImage, ref TextBox txtSound, ref TextBox txtNotes, ref TextBox txtDiffLevel, ref ComboBox cmbBook)
		{
			DataSet ds = new DataSet();
						
			MyDatabase.GetTopics(SectionID,TopicID,ref ds);
			LoadBooks(ref cmbBook);
			foreach(DataTable dtb in ds.Tables)
			{
			
				txtTitle.DataBindings.Add("text",dtb,"Title");
				if(SectionID == 4)
					txtTape.DataBindings.Add("text",dtb,"Passages");
				else if(SectionID == 7)
					txtPassages.DataBindings.Add("text",dtb,"Passages");
				if(dtb.Columns["ImageFile"] != null)
					txtImage.DataBindings.Add("text",dtb,"ImageFile");
				if(dtb.Columns["SoundFile"] != null)
					txtSound.DataBindings.Add("text",dtb,"SoundFile");
				if(dtb.Columns["Notes"] != null)
					txtNotes.DataBindings.Add("text",dtb,"Notes");
				if(dtb.Columns["DiffLevel"] != null)
					txtDiffLevel.DataBindings.Add("text",dtb,"DiffLevel");
				foreach (Object obj in cmbBook.Items)
				{
					if(obj.ToString().StartsWith(dtb.Rows[0].ItemArray[9].ToString()))
						cmbBook.SelectedItem = obj;
				}
			}
		}

		static public Boolean UpdateTopic(long SectionID, long TopicID, TextBox txtTitle,TextBox txtPassages, TextBox txtTape, TextBox txtImage, TextBox txtSound, TextBox txtNotes, TextBox txtDiffLevel, ComboBox cmbBook)
		{
			string stPass = "";
			if(SectionID ==4)
				stPass = txtTape.Text;
			else if(SectionID==7)
				stPass = txtPassages.Text;
			string stBook =  cmbBook.SelectedItem.ToString().Substring(0,cmbBook.SelectedItem.ToString().IndexOf("-"));
			string strsql = "UPDATE tblTopic SET Title=\"" + txtTitle.Text + "\", Passages=\"" + stPass + "\", SoundFile=\"" + txtSound.Text + "\", ImageFile=\"" + txtImage.Text + "\", Notes=\"" + txtNotes.Text + "\", DiffLevel=" + txtDiffLevel.Text + ", BookID=\"" + stBook + "\", LastUpdate=\"" + DateTime.Today.ToString() + "\"   WHERE TopicID=" + TopicID.ToString(); 
			return MyDatabase.ExecuteNonQuery(strsql);
			
		}
		static public Boolean AddTopic(long SectionID, long TopicID, TextBox txtTitle,TextBox txtPassages, TextBox txtTape, TextBox txtImage, TextBox txtSound, TextBox txtNotes, TextBox txtDiffLevel, ComboBox cmbBook)
		{
			string stPass = "";
			if(SectionID ==4)
				stPass = txtTape.Text;
			else if(SectionID==7)
				stPass = txtPassages.Text;
			string stBook =  cmbBook.SelectedItem.ToString().Substring(0,cmbBook.SelectedItem.ToString().IndexOf("-"));
			string strsql = "INSERT INTO tblTopic(SectionID,Title,Passages,ImageFile,SoundFile,DiffLevel,BookID,Notes,LastUpdate) ";
			strsql += " VALUES(" + SectionID.ToString() + ", \"" + txtTitle.Text + "\", \"" + stPass + "\", \"" + txtImage.Text + "\", \"" + txtSound.Text + "\", " + txtDiffLevel.Text + ", \"" + stBook + "\", \"" + txtNotes.Text + "\", \"" + DateTime.Today.ToString() + "\")"; 
			
			return MyDatabase.ExecuteNonQuery(strsql);
			
		}
		static public void LoadBooks(ListBox  lstboxBook)
		{
			lstboxBook.SelectionMode = SelectionMode.MultiExtended;
			lstboxBook.Items.Clear();

			DataSet ds2 = new DataSet();	
			MyDatabase.GetBookList(ref ds2);
			foreach(DataTable dtb in ds2.Tables)
			{
				foreach (DataRow dr in dtb.Rows)
				{
					string stTmp = dr.ItemArray[0].ToString() + "-" + dr.ItemArray[1].ToString();
					lstboxBook.Items.Add(stTmp);
				}
			}
			for (int k=0; k<lstboxBook.Items.Count; k++)
				lstboxBook.SetSelected(k, true);
		}
		static public void LoadBooks(ref ComboBox  cmbBook)
		{
			DataSet ds2 = new DataSet();	
			MyDatabase.GetBookList(ref ds2);
			foreach(DataTable dtb in ds2.Tables)
			{
				foreach (DataRow dr in dtb.Rows)
				{
					string stTmp = dr.ItemArray[0].ToString() + "-" + dr.ItemArray[1].ToString();
					cmbBook.Items.Add(stTmp);
				}
			}	
			
			if(cmbBook.Items.Count>0)
				cmbBook.SelectedIndex = 0; // incompleted --
			//set selected book in cmb
		}
		static public bool DeleteTopic(long TopicID)
		{
			if(MyDatabase.IsHasQuestions(TopicID))
				return false;
			string strsql = "DELETE FROM tblTopic WHERE TopicID=" + TopicID;
			return MyDatabase.ExecuteNonQuery(strsql);
		}
		#endregion

		#region /* Cac thao tac tren Question : LOAD, ADD, UPDATE, DEL */
		static public void LoadQuestion(long TopicID, long QuestionID, ref TextBox txtQuestion, ref TextBox txtChoiceA, ref TextBox txtChoiceB, ref TextBox txtChoiceC, ref TextBox txtChoiceD,ref  TextBox txtTape, ref TextBox txtImage, ref TextBox txtSound, ref TextBox txtNotes, ref TextBox txtAnswer, ref TextBox txtDiffLevel, ref ComboBox cmbBook)
		{
			DataSet ds = new DataSet();
			
			MyDatabase.GetQuestions(TopicID,QuestionID,ref ds);
			LoadBooks(ref cmbBook);
			foreach(DataTable dtb in ds.Tables)
			{
			
				txtQuestion.DataBindings.Add("text",dtb,"QuestionText");
				if(dtb.Columns["Tape"] != null)
					txtTape.DataBindings.Add("text",dtb,"Tape");
				if(dtb.Columns["ImageFile"] != null)
					txtImage.DataBindings.Add("text",dtb,"ImageFile");
				if(dtb.Columns["SoundFile"] != null)
					txtSound.DataBindings.Add("text",dtb,"SoundFile");
				if(dtb.Columns["Notes"] != null)
					txtNotes.DataBindings.Add("text",dtb,"Notes");
				if(dtb.Columns["DiffLevel"] != null)
					txtDiffLevel.DataBindings.Add("text",dtb,"DiffLevel");
				if(dtb.Columns["ChoiceA"] != null)
					txtChoiceA.DataBindings.Add("text",dtb,"ChoiceA");
				if(dtb.Columns["ChoiceB"] != null)
					txtChoiceB.DataBindings.Add("text",dtb,"ChoiceB");
				if(dtb.Columns["ChoiceC"] != null)
					txtChoiceC.DataBindings.Add("text",dtb,"ChoiceC");
				if(dtb.Columns["ChoiceD"] != null)
					txtChoiceD.DataBindings.Add("text",dtb,"ChoiceD");
				if(dtb.Columns["Answer"] != null)
					txtAnswer.DataBindings.Add("text",dtb,"Answer");
				foreach (Object obj in cmbBook.Items)
				{
					if(obj.ToString().StartsWith(dtb.Rows[0].ItemArray[9].ToString()))
						cmbBook.SelectedItem = obj;
				}
						
			}
			
		}

		static public Boolean UpdateQuestion(long TopicID, long QuestionID, TextBox txtQuestion, TextBox txtChoiceA, TextBox txtChoiceB, TextBox txtChoiceC, TextBox txtChoiceD, TextBox txtTape, TextBox txtImage, TextBox txtSound, TextBox txtNotes, TextBox txtAnswer, TextBox txtDiffLevel, ComboBox cmbBook)
		{
			string stBook =  cmbBook.SelectedItem.ToString().Substring(0,cmbBook.SelectedItem.ToString().IndexOf("-"));
			string strsql = "UPDATE tblQuestion SET QuestionText=\"" + txtQuestion.Text + "\", ChoiceA=\"" + txtChoiceA.Text + "\", ChoiceB=\"" + txtChoiceB.Text + "\", ChoiceC=\"" + txtChoiceC.Text + "\", ChoiceD=\"" + txtChoiceD.Text + "\", SoundFile=\"" + txtSound.Text + "\", Answer=\"" + txtAnswer.Text + "\", ImageFile=\"" + txtImage.Text + "\", Notes=\"" + txtNotes.Text + "\", DiffLevel=" + txtDiffLevel.Text + ", BookID=\"" + stBook + "\", LastUpdate=\"" + DateTime.Today.ToString() + "\" WHERE QuestionID=" + QuestionID; 
			return MyDatabase.ExecuteNonQuery(strsql);
			
		}
		
		static public Boolean AddQuestion(long TopicID, long QuestionID, TextBox txtQuestion, TextBox txtChoiceA, TextBox txtChoiceB, TextBox txtChoiceC, TextBox txtChoiceD, TextBox txtTape, TextBox txtImage, TextBox txtSound, TextBox txtNotes, TextBox txtAnswer, TextBox txtDiffLevel, ComboBox cmbBook)
		{
			string stBook =  cmbBook.SelectedItem.ToString().Substring(0,cmbBook.SelectedItem.ToString().IndexOf("-"));
			string strsql = "INSERT INTO tblQuestion(TopicID,QuestionText,Tape,ImageFile,SoundFile,ChoiceA,ChoiceB,ChoiceC,ChoiceD,Answer,DiffLevel,BookID,Notes,LastUpdate)";
			strsql += " VALUES(" + TopicID.ToString() + ",\"" + txtQuestion.Text + "\",\"" + txtTape.Text + "\",\"" + txtImage.Text + "\",\"" + txtSound.Text + "\",\"" + txtChoiceA.Text + "\",\"" + txtChoiceB.Text + "\",\"" + txtChoiceC.Text + "\",\"" + txtChoiceD.Text + "\",\"" + txtAnswer.Text + "\"," + txtDiffLevel.Text + ",\"" + stBook + "\",\"" + txtNotes.Text + "\",\"" + DateTime.Today.ToString() + "\")"; 
			
			return MyDatabase.ExecuteNonQuery(strsql);
			
		}
		static public bool DeleteQuestion(long QuestionID)
		{
			string strsql = "DELETE FROM tblQuestion WHERE QuestionID=" + QuestionID;
			return MyDatabase.ExecuteNonQuery(strsql);
			
		}		
		#endregion

		#region /* Load du lieu tu DB ==> ExamTestTreeView */
		static public void LoadTestDB2Tree(TreeView trv)
		{
			TreeNode nodeS = new TreeNode("NULL"); 
			TreeNode nodeT = new TreeNode("NULL"); 
			
			DataSet myDataSet = new DataSet();
			ResetTreeViewExam(trv);
			if(TestID > 0)
				MyDatabase.CreateTempTesttbl(TestID);
			MyDatabase.GetTempTestDetails(0, 0, ref myDataSet);
			foreach(DataTable myTable in myDataSet.Tables)
			{
				long nOrder = 0;
				foreach(DataRow myRow in myTable.Rows)
				{
					string sId = myRow["SectionID"].ToString();
					if (!htID2TreeNode.Contains( "ES"+sId ))
					{
						nodeS = new TreeNode(myRow["STitle"].ToString());
						nodeS.Tag = "ES"+sId;
						htID2TreeNode[nodeS.Tag] = nodeS;

						trv.Nodes.Add(nodeS);
					}
					else
						nodeS = (TreeNode)htID2TreeNode["ES"+sId]; 


					if (sId == "4" || sId == "7")
					{
						string tId = myRow["TopicID"].ToString();
						if (!htID2TreeNode.Contains( "ET"+tId ))
						{
							string sTFieldTitle = "TTitle";
							if (sId=="4")	sTFieldTitle = "TPassages";
							string stTittle = myRow[sTFieldTitle].ToString();
							int index = stTittle.IndexOf("#");
							if(index != -1)
								stTittle = stTittle.Substring(0, index);
							
							nodeT = new TreeNode(stTittle);
							nodeT.Tag = "ET"+tId;
							htID2TreeNode[nodeT.Tag] = nodeT;
							
							nodeS.Nodes.Add( nodeT );
						}
						else
							nodeT = (TreeNode)htID2TreeNode["ET"+tId]; 
					}
					
					nOrder++;
					TreeNode nodeQ = new TreeNode(nOrder.ToString()+". "+GetQuestionText(myRow));
					if(sId == "6")
					{
						string stTemp = nodeQ.Text;
						int index = stTemp.IndexOf("<br>");
						if(index > -1)
							stTemp = stTemp.Substring(0, index);
						stTemp = stTemp.Replace("&nbsp;", " ");
						stTemp = stTemp.Replace("<U>", "");
						stTemp = stTemp.Replace("</U>", "");
						nodeQ.Text = stTemp;
					}
					nodeQ.Tag = "EQ"+myRow["QuestionID"].ToString();
					htID2TreeNode[nodeQ.Tag] = nodeQ;

					if (sId == "4" || sId == "7")
						nodeT.Nodes.Add(nodeQ);
					else
						nodeS.Nodes.Add(nodeQ);
				}
			}
		}
		
		
		static public void LoadTests2ListView(ListView lv)
		{
			DataSet ds = new DataSet();
			MyDatabase.GetTests( ref ds );
			lv.Items.Clear();
			foreach(DataTable dtb in ds.Tables)
			{
				foreach(DataRow dr in dtb.Rows)
				{
					ListViewItem item = new ListViewItem(dr.ItemArray[1].ToString() + ".etb", 1);
					item.Tag = dr.ItemArray[0].ToString();
					item.ImageIndex = 0;
					
					for(int i = 2; i< dr.ItemArray.Length; i++)
						item.SubItems.Add(dr.ItemArray[i].ToString());

					lv.Items.Add(item);
				}
			}
			
		}
		static public void ResetTreeViewExam(TreeView trv)
		{
			foreach(TreeNode nodeS in trv.Nodes)
			{
				if(htID2TreeNode.Contains(nodeS.Tag.ToString()))
					htID2TreeNode.Remove(nodeS.Tag.ToString());
				foreach(TreeNode nodeT in nodeS.Nodes)
				{
					if(htID2TreeNode.Contains(nodeT.Tag.ToString()))
						htID2TreeNode.Remove(nodeT.Tag.ToString());
					if(nodeT.Tag.ToString().StartsWith("ET"))
					{
						foreach(TreeNode nodeQ in nodeT.Nodes)
						{
							if(htID2TreeNode.Contains(nodeQ.Tag.ToString()))
								htID2TreeNode.Remove(nodeQ.Tag.ToString());
						}

					}
				}
			}
			trv.Nodes.Clear();
		}
		static public void ResetTreeViewQues(TreeView trv)
		{
			foreach(TreeNode nodeS in trv.Nodes)
			{
				nodeS.Checked = false;
				foreach(TreeNode nodeT in nodeS.Nodes)
				{
					nodeT.Checked = false;
					if(nodeT.Tag.ToString().StartsWith("T"))
					{
						foreach(TreeNode nodeQ in nodeT.Nodes)
						{
							nodeQ.Checked = false;
						}

					}
				}
			}
		}
		#endregion
		
		#region /* Insert Test and Update Test */
		static public void InsertTest(string Direction1A, string Direction1B, string Direction1C, string Direction1D, string Direction2A, string Direction2B, string Direction3, string TheEnd1A, string TheEnd1B, string TheEnd1C, string TheEnd1D, string TheEnd2A, string TheEnd2B, string TheEnd3)
		{
			MyDatabase.UpdateTempTest();
			MyDatabase.TempToDetailTest();
			MyDatabase.InsertTest(ExamCode, dtCreate, stClass, stSchool, Duration, stNotes, Direction1A, Direction1B, Direction1C, Direction1D, Direction2A, Direction2B, Direction3, TheEnd1A, TheEnd1B, TheEnd1C, TheEnd1D, TheEnd2A, TheEnd2B, TheEnd3);
	
		}
		static public void UpdateTest(long ExamID, string Direction1A, string Direction1B, string Direction1C, string Direction1D, string Direction2A, string Direction2B, string Direction3, string TheEnd1A, string TheEnd1B, string TheEnd1C, string TheEnd1D, string TheEnd2A, string TheEnd2B, string TheEnd3)
		{
			MyDatabase.TempToDetailTest();
			MyDatabase.UpdateTest(ExamID, ExamCode, dtCreate, stClass, stSchool, Duration, stNotes, Direction1A, Direction1B, Direction1C, Direction1D, Direction2A, Direction2B, Direction3, TheEnd1A, TheEnd1B, TheEnd1C, TheEnd1D, TheEnd2A, TheEnd2B, TheEnd3);
	
		}
		#endregion

		#region /* Check/Uncheck vao cay ==> Check/Uncheck cac node section topic, Question */
		static public void UnCheckAndRemoveNode(TreeNode nodeUnCheck, TreeView trv)
		{
			if(!nodeUnCheck.Checked)
			{
				if(nodeUnCheck.Tag.ToString().StartsWith("T"))
				{
					TreeNode nodeT = (TreeNode)htID2TreeNode["E" + nodeUnCheck.Tag.ToString()];
					TreeNode nodeS = nodeT.Parent;
					
					//remove topic
					nodeT.Remove();
					htID2TreeNode.Remove(nodeT.Tag.ToString());
					TreeNode nodeTopic = (TreeNode)htID2TreeNode[nodeT.Tag.ToString().Substring(1)];
					nodeTopic.Checked = false;
					foreach(TreeNode node in nodeT.Nodes)
					{
						htID2TreeNode.Remove(node.Tag.ToString());
						TreeNode nodeQ = (TreeNode)htID2TreeNode[node.Tag.ToString().Substring(1)];
						nodeQ.Checked = false;
					}
					if(nodeS.Nodes.Count == 0)
					{
						//remove section
						nodeS.Remove();
						htID2TreeNode.Remove(nodeS.Tag.ToString());
						TreeNode nodeSection = (TreeNode)htID2TreeNode[nodeS.Tag.ToString().Substring(1)];
						nodeSection.Checked = false;
					}
				} 
				else if(nodeUnCheck.Tag.ToString().StartsWith("Q"))
				{
					
					if(htID2TreeNode.Contains("E" + nodeUnCheck.Tag.ToString()))
					{
						TreeNode nodeQ = (TreeNode)htID2TreeNode["E" + nodeUnCheck.Tag.ToString()];
					
						TreeNode node = nodeQ.Parent;
						nodeQ.Remove();
						if(node.Tag.ToString().StartsWith("ET"))
						{
							TreeNode nodeS = node.Parent;
							if(node.Nodes.Count == 0)
							{
								htID2TreeNode.Remove(node.Tag.ToString());
								TreeNode nodeTTmp = (TreeNode)htID2TreeNode[node.Tag.ToString().Substring(1)];
								nodeTTmp.Checked = false;
								node.Remove();
							
							}
							if(nodeS.Nodes.Count == 0)
							{
								nodeS.Remove();
								htID2TreeNode.Remove(nodeS.Tag.ToString());
								TreeNode nodeSTmp = (TreeNode)htID2TreeNode[nodeS.Tag.ToString().Substring(1)];
								nodeSTmp.Checked = false;
							}				
						}
						else
						{
							if(node.Nodes.Count == 0)
							{
								node.Remove();
								htID2TreeNode.Remove(node.Tag.ToString());
								TreeNode nodeTTmp = (TreeNode)htID2TreeNode[node.Tag.ToString().Substring(1)];
								nodeTTmp.Checked = false;
							}
						}
					}


					TreeNode nodeTopic = nodeUnCheck.Parent;
					TreeNode nodeSection = nodeUnCheck.Parent.Parent;
					string sTag = nodeSection.Tag.ToString();
					if (sTag=="S4" || sTag=="S7")
						return;
					bool isBreak = false;;
					foreach (TreeNode n in nodeTopic.Nodes)
						if (n.Checked)
						{
							isBreak = true;
							break;
						}
					if (!isBreak)
						nodeTopic.Checked = false;
					isBreak = false;;
					foreach (TreeNode n in nodeSection.Nodes)
						if (n.Checked)
						{
							isBreak = true;
							break;
						}
					if (!isBreak)
						nodeSection.Checked = false;
				}
			}
		}

		static public void CheckAndAddNode(TreeNode nodeCheck, TreeView trv)
		{
			if(nodeCheck.Tag.ToString().StartsWith("T"))
			{
				TreeNode nodeSection = nodeCheck.Parent;
				long SectionID = Convert.ToInt64(nodeSection.Tag.ToString().Substring(1));
				TreeNode nodeTopic = nodeCheck;
				nodeTopic.Checked = true;
				if(!htID2TreeNode.Contains("E" + nodeSection.Tag.ToString()))
				{
					//add section
					TreeNode node = new TreeNode(nodeSection.Text);
					node.Tag = "E" + nodeSection.Tag.ToString();
					htID2TreeNode[node.Tag] = node;
					trv.Nodes.Add( node );
					TreeNode nodeSTmp = (TreeNode)htID2TreeNode[node.Tag.ToString().Substring(1)];
					nodeSTmp.Checked = true;
				
				} 
				TreeNode nodeS = (TreeNode)htID2TreeNode["E" + nodeSection.Tag.ToString()];
				if(!htID2TreeNode.Contains("E" + nodeTopic.Tag.ToString()))
				{
					//add topic
					TreeNode node = new TreeNode(nodeTopic.Text);
					node.Tag = "E" + nodeTopic.Tag.ToString();
					htID2TreeNode[node.Tag] = node;
					nodeS.Nodes.Add( node );
				}
				TreeNode nodeT = (TreeNode)htID2TreeNode["E" + nodeTopic.Tag.ToString()];
				nodeT.Nodes.Clear();
				foreach(TreeNode nodeQues in nodeTopic.Nodes)
				{
					nodeQues.Checked = true;
					TreeNode nodeQ = new TreeNode(nodeQues.Text);
					nodeQ.Tag = "E" + nodeQues.Tag.ToString();
					htID2TreeNode[nodeQ.Tag] = nodeQ;
					nodeT.Nodes.Add( nodeQ );

				}
			}
				
			else if(nodeCheck.Tag.ToString().StartsWith("Q"))
			{
				TreeNode nodeSection = nodeCheck.Parent.Parent;
				long SectionID = Convert.ToInt64(nodeSection.Tag.ToString().Substring(1));
				TreeNode nodeTopic = nodeCheck.Parent;
				if(!htID2TreeNode.Contains("E" + nodeSection.Tag.ToString()))
				{
					//add section
					TreeNode node = new TreeNode(nodeSection.Text);
					node.Tag = "E" + nodeSection.Tag.ToString();
					htID2TreeNode[node.Tag] = node;
					trv.Nodes.Add( node );
					TreeNode nodeSTmp = (TreeNode)htID2TreeNode[node.Tag.ToString().Substring(1)];
					nodeSTmp.Checked = true;
				} 
				TreeNode nodeS = (TreeNode)htID2TreeNode["E" + nodeSection.Tag.ToString()];
				if(SectionID == 4 || SectionID == 7)
				{
					if(!htID2TreeNode.Contains("E" + nodeTopic.Tag.ToString()))
					{
						//add topic
						TreeNode node = new TreeNode(nodeTopic.Text);
						node.Tag = "E" + nodeTopic.Tag.ToString();
						htID2TreeNode[node.Tag] = node;
						nodeS.Nodes.Add( node );
						TreeNode nodeTTmp = (TreeNode)htID2TreeNode[node.Tag.ToString().Substring(1)];
						nodeTTmp.Checked = true;
					}
					nodeS = (TreeNode)htID2TreeNode["E" + nodeTopic.Tag.ToString()];					
				}
				TreeNode nodeQ = new TreeNode(nodeCheck.Text);
				nodeQ.Tag = "E" + nodeCheck.Tag.ToString();
				htID2TreeNode[nodeQ.Tag] = nodeQ;
				nodeS.Nodes.Add( nodeQ );
			}
			if (nodeCheck.Parent != null) nodeCheck.Parent.Checked = true;
			if (nodeCheck.Parent.Parent != null) nodeCheck.Parent.Parent.Checked = true;
		}
		
		static public void MapCheckedNodeOnTrees(TreeView trv)
		{
			
			foreach(TreeNode nodeS in trv.Nodes)
			{
				if(htID2TreeNode.Contains( nodeS.Tag.ToString().Substring(1)))
				{
					TreeNode nodeSection = (TreeNode)htID2TreeNode[nodeS.Tag.ToString().Substring(1)];
					nodeSection.Checked = true;
								
					foreach(TreeNode nodeT in nodeS.Nodes)
					{
						if(htID2TreeNode.Contains( nodeT.Tag.ToString().Substring(1)))
						{
							TreeNode nodeTopic =  (TreeNode)htID2TreeNode[nodeT.Tag.ToString().Substring(1)];
							nodeTopic.Checked = true;
							nodeTopic.Parent.Checked = true;
							foreach(TreeNode nodeQ in nodeT.Nodes)
							{
								if(htID2TreeNode.Contains( nodeQ.Tag.ToString().Substring(1)))
								{
									TreeNode nodeQuestion = (TreeNode)htID2TreeNode[nodeQ.Tag.ToString().Substring(1)];
									nodeQuestion.Checked = true;
									nodeQuestion.Parent.Checked = true;
								}
							}							
						}								
					}					
				}
			}
		}	
		#endregion

		#region /* Change the index of section, topic, ques in TreeViewExamTest */
		static public void MoveUp(TreeView trv)
		{
			TreeNode node = trv.SelectedNode;
			if(node == null)
				return;
			if(node.Tag.ToString().StartsWith("ES")) //section
			{
				int index = trv.Nodes.IndexOf(node);
				if(index > 0)
				{
					trv.Nodes.Remove(node);
					trv.Nodes.Insert(index - 1, node);
					trv.SelectedNode = node;
				}

			}else if(node.Tag.ToString().StartsWith("ET")) //section
			{
				TreeNode nodeS = node.Parent;
                int index = nodeS.Nodes.IndexOf(node);
				if(index > 0)
				{
					nodeS.Nodes.Remove(node);
					nodeS.Nodes.Insert(index - 1, node);
					trv.SelectedNode = node;
				}

			}
			else if(node.Tag.ToString().StartsWith("EQ")) //section
			{
				TreeNode nodeT = node.Parent;
				int index = nodeT.Nodes.IndexOf(node);
				if(index > 0)
				{
					nodeT.Nodes.Remove(node);
					nodeT.Nodes.Insert(index - 1, node);
					trv.SelectedNode = node;
				}

			}
		}
		static public void MoveDown(TreeView trv)
		{
			TreeNode node = trv.SelectedNode;
			if(node == null)
				return;
			if(node.Tag.ToString().StartsWith("ES")) //section
			{
				int index = trv.Nodes.IndexOf(node);
				if(index < trv.Nodes.Count - 1)
				{
					trv.Nodes.Remove(node);
					trv.Nodes.Insert(index + 1, node);
					trv.SelectedNode = node;
				}

			}
			else if(node.Tag.ToString().StartsWith("ET")) //section
			{
				TreeNode nodeS = node.Parent;
				int index = nodeS.Nodes.IndexOf(node);
				if(index < nodeS.Nodes.Count - 1)
				{
					nodeS.Nodes.Remove(node);
					nodeS.Nodes.Insert(index + 1, node);
					trv.SelectedNode = node;
				}

			}
			else if(node.Tag.ToString().StartsWith("EQ")) //section
			{
				TreeNode nodeT = node.Parent;
				int index = nodeT.Nodes.IndexOf(node);
				if(index < nodeT.Nodes.Count - 1)
				{
					nodeT.Nodes.Remove(node);
					nodeT.Nodes.Insert(index + 1, node);
					trv.SelectedNode = node;
				}

			}
		}
		static public void DeleteQuestionFromTree(TreeNode node,TreeView trv)
		{
			TreeNode nodeQ = (TreeNode)htID2TreeNode[node.Tag.ToString().Substring(1)];
			nodeQ.Checked = false;
			UnCheckAndRemoveNode(nodeQ, trv);
		}
		
		static public void ReOrderNodes(TreeView trv)
		{
			int nOrder = 0;
			foreach(TreeNode nodeS in trv.Nodes)
			{
				foreach(TreeNode nodeT in nodeS.Nodes)
				{
					if (nodeT.Tag.ToString().StartsWith("EQ"))
					{
						string sText = nodeT.Text.Substring(nodeT.Text.IndexOf(".")+1);
						nodeT.Text = (nOrder+1).ToString() + ". " + sText;
						nOrder++;
					}
					foreach(TreeNode nodeQ in nodeT.Nodes)
					{
						if (nodeQ.Tag.ToString().StartsWith("EQ"))
						{
							string sText = nodeQ.Text.Substring(nodeQ.Text.IndexOf(".")+1);
							nodeQ.Text = (nOrder+1).ToString() + ". " + sText;
							nOrder++;
						}
					}							
				}					
			}
		}
		#endregion

		#region /* Xu ly temp test */
		static public void TreeView2DB(TreeView trv)
		{
			long nOrder = 1;
			string sTag = "";
			long QuesID = 0;
			MyDatabase.ResetTempTest();
			foreach(TreeNode nodeS in trv.Nodes)
			{
				foreach(TreeNode nodeT in nodeS.Nodes)
				{
					if(nodeT.Tag.ToString().StartsWith("ET"))
					{
						foreach(TreeNode nodeQ in nodeT.Nodes)
						{
							sTag = nodeQ.Tag.ToString();
							QuesID = Convert.ToInt64(sTag.Substring(2));
							MyDatabase.InsertQuesToTmpTest(TestID,QuesID, nOrder);
							nOrder++;
						}

					}
					else if(nodeT.Tag.ToString().StartsWith("EQ"))
					{
						sTag = nodeT.Tag.ToString();
						QuesID = Convert.ToInt64(sTag.Substring(2));
						MyDatabase.InsertQuesToTmpTest(TestID,QuesID, nOrder);
						nOrder++;
					}
					
				}
			}
		}
		#endregion

		#region /* Lay cac thong tin chung */
		static public void LoadGlobalInfo(ref string Direction1A, ref string Direction1B, ref string Direction1C, ref string Direction1D, ref string Direction2A, ref string Direction2B, ref string Direction3, ref string TheEnd1A, ref string TheEnd1B, ref string TheEnd1C, ref string TheEnd1D, ref string TheEnd2A, ref string TheEnd2B, ref string TheEnd3)
		{
			string stQuery = "SELECT Direction, TheEnd FROM tblSection";
			DataSet ds = new DataSet();
			MyDatabase.ExecuteQuery(stQuery, ref ds);
			foreach(DataTable dtb in ds.Tables)
			{
				Direction1A = dtb.Rows[0].ItemArray[0].ToString();
				Direction1B = dtb.Rows[1].ItemArray[0].ToString();
				Direction1C = dtb.Rows[2].ItemArray[0].ToString();
				Direction1D = dtb.Rows[3].ItemArray[0].ToString();
				Direction2A = dtb.Rows[4].ItemArray[0].ToString();
				Direction2B = dtb.Rows[5].ItemArray[0].ToString();
				Direction3  = dtb.Rows[6].ItemArray[0].ToString();
				// the end
				TheEnd1A = dtb.Rows[0].ItemArray[1].ToString();
				TheEnd1B = dtb.Rows[1].ItemArray[1].ToString();
				TheEnd1C = dtb.Rows[2].ItemArray[1].ToString();
				TheEnd1D = dtb.Rows[3].ItemArray[1].ToString();
				TheEnd2A = dtb.Rows[4].ItemArray[1].ToString();
				TheEnd2B = dtb.Rows[5].ItemArray[1].ToString();
				TheEnd3  = dtb.Rows[6].ItemArray[1].ToString();
			}
		}
		#endregion
		
		#region /*  Tao Exam Tape */
		static public void MakeExamTape(long ExamID, TreeView trv,string stSrcFolder, string stDesFolder)
		{
			string stTemp = stSrcFolder;
			string stDesQuestion = "",stSrcQuestion = "", stQuesFile = "", stToFile = "", stAndFile = "", stThroughFile = "";
			string stDesTopic = "",stSrcTopic = "", stTopNum = "", stQuesNum = "";
			stSrcFolder = stSrcFolder + "Numbers\\" ;
			
			stAndFile = stSrcFolder + "And.wav";
			stThroughFile = stSrcFolder + "Through.wav";
			int nOrder = 1;
			foreach(TreeNode nodeS in trv.Nodes )
			{
				long SecID = Convert.ToInt64(nodeS.Tag.ToString().Substring(2));
				if(SecID < 5)
				{
					//copy Direction  vao thu muc
					string stFileDirection = "Part" + SecID.ToString() + "_Direction.wav"; 
					string stFileBegin = "Part" + SecID.ToString() + "_Begin.wav"; 
					if(File.Exists(stSrcFolder + stFileDirection))
						File.Copy(stSrcFolder + stFileDirection, stDesFolder + stFileDirection, true);
					if(File.Exists(stSrcFolder + stFileBegin))
						File.Copy(stSrcFolder + stFileBegin, stDesFolder + stFileBegin, true);
					if(SecID < 4)
					{
						
						//create question
						foreach(TreeNode nodeQ in nodeS.Nodes)
						{
							string stQuesID = nodeQ.Tag.ToString().Substring(2);
							TreeNode nodeQuestion = (TreeNode)htID2TreeNode[nodeQ.Tag.ToString().Substring(1)];
							TreeNode nodeTopic = nodeQuestion.Parent;
							string stTopID = nodeTopic.Tag.ToString().Substring(1); 
							//order
							string stOrder = nOrder.ToString();
							if(stOrder.Length < 2)
								stOrder = stOrder.PadLeft(2, '0');
							
							// file destination
							stDesQuestion = "Part" + SecID.ToString() + "_Ques" + stOrder + "B.wav";
							stDesQuestion = stDesFolder + stDesQuestion;
							// tao ten file sound ung voi QuesID
							if(stQuesID.Length < 5)
								stQuesID = stQuesID.PadLeft(5,'0');
							if(stTopID.Length < 5)
								stTopID = stTopID.PadLeft(5,'0');
							stSrcQuestion = "S" + SecID.ToString() + "T" + stTopID + "Q" + stQuesID + ".wav";
							stSrcQuestion = stTemp + stSrcQuestion;
							//copy file sound vao thu muc output
							if(File.Exists(stSrcQuestion))
								File.Copy(stSrcQuestion, stDesQuestion, true);
							// tao file question Number
							stQuesNum = "Part" + SecID.ToString() + "_Ques" + stOrder + "A.wav";
							stQuesNum = stDesFolder + stQuesNum;
							//copy file sound vao thu muc output
							stQuesFile =  stSrcFolder + stOrder + ".wav";
							if(File.Exists(stQuesFile))
								File.Copy(stQuesFile, stQuesNum, true);
						//	MakeSoundFile(stQuesFile, stSrcFolder + stOrder + ".wav", nSilenAfterQues, stQuesNum);
							nOrder++;
						}
						
					}
					else
					{
						// xu ly topic
						stQuesFile = stSrcFolder + "Question.wav";
						foreach(TreeNode nodeT in nodeS.Nodes)
						{
							string stTmpSound = "Tmp.wav";
							string stTopID = nodeT.Tag.ToString().Substring(2);
							TreeNode nodeTopic = (TreeNode)htID2TreeNode[nodeT.Tag.ToString().Substring(1)];
							//order
							int nOrderFrom = nOrder;
							int nOrderTo = nOrder + nodeTopic.Nodes.Count - 1;
							string stOrderFrom = nOrderFrom.ToString();
							if(stOrderFrom.Length < 2)
								stOrderFrom = stOrderFrom.PadLeft(2, '0');
							string stOrderTo = nOrderTo.ToString();
							if(stOrderTo.Length < 2)
								stOrderTo = stOrderTo.PadLeft(2, '0');
							
							// file destination
							stDesTopic = "Part" + SecID.ToString() + "_Top" + stOrderFrom + "_" + stOrderTo  + "B.wav";
							stDesTopic = stDesFolder + stDesTopic;
							// tao ten file sound ung voi TopID
							if(stTopID.Length < 5)
								stTopID = stTopID.PadLeft(5,'0');
							if(stTopID.Length < 5)
								stTopID = stTopID.PadLeft(5,'0');
							stSrcTopic = "S" + SecID.ToString() + "T" + stTopID + ".wav";
							stSrcTopic = stTemp + stSrcTopic;
							//copy file sound vao thu muc output
							if(File.Exists(stSrcTopic))
								File.Copy(stSrcTopic, stDesTopic, true);
							// tao file question Number
							if(nodeTopic.Nodes.Count > 2)
								stToFile = stThroughFile;
							else 
								stToFile  = stAndFile;
							stTopNum = "Part" + SecID.ToString() + "_Top" + stOrderFrom + "_" + stOrderTo + "A.wav";
							stTopNum = stDesFolder + stTopNum;
						//	MakeSoundFile(stQuesFile, stSrcFolder + "Wave" + stOrderFrom + ".wav", 2, stTopNum);
						//	MakeSoundFile(stTopNum, stToFile, 2, stTmpSound);
						//	MakeSoundFile(stTmpSound, stSrcFolder + "Wave" + stOrderTo + ".wav", 2, stTopNum);
						//	MakeSoundFile(stQuesFile, stSrcFolder + "Wave" + stOrderFrom + ".wav", 2, stTopNum);
						
						//	MakeSoundFile(stSrcFolder + "Wave" + stOrderFrom + ".wav", stToFile, 2, stTopNum);
						//	MakeSoundFile(stTopNum, stSrcFolder + "Wave" + stOrderTo + ".wav", 2, stTmpSound);
						//	MakeSoundFile(stQuesFile, stTmpSound, 2, stTopNum);
							string stTemp1 = "tmpo.wav";
							MakeSoundFile(stQuesFile, stSrcFolder + "Wave" + stOrderFrom + ".wav", 2, stTemp1);
							MakeSoundFile(stToFile, stSrcFolder + "Wave" + stOrderTo + ".wav", 2, stTmpSound);
							MakeSoundFile(stTemp1, stTmpSound, 2, stTopNum);
							if(File.Exists(stTmpSound))
								File.Delete(stTmpSound);
							if(File.Exists(stTemp1))
								File.Delete(stTemp1);
							nOrder = nOrderTo + 1;
							for(int k = nOrderFrom; k <= nOrderTo; k++)
							{
								stSrcQuestion = stSrcFolder + k.ToString() + ".wav";
								stDesQuestion = "Part" + SecID.ToString() + "_Top" + stOrderFrom + "_" + stOrderTo + "C" + k.ToString() + ".wav";
								stDesQuestion = stDesFolder + stDesQuestion;
								if(File.Exists(stSrcQuestion))
									File.Copy(stSrcQuestion, stDesQuestion, true);
							}
						
						}
					}
					
				}
			}

		}
		static public void MakeSoundFile(string stSrcFile1, string stSrcFile2, int DelayTime, string stDesFile)
		{
			string stTemp = "temp.wav";
			try
			{
			
				WaveReader	wr1 = new WaveReader(stSrcFile2);
				Delay		de1 = new Delay(DelayTime*2000);
				WaveWriter	wwl = new WaveWriter(stTemp, wr1.NumChannels, wr1.SampleRate, wr1.BitsPerSamples, 1, true);
			
				de1.Input = wr1;
				wwl.Input = de1;
				int k = 0;
				int inter = wwl.Interations;

				for(k = 0; k < inter; k++)
				{
					wr1.DoProcess();
					de1.DoProcess();
					wwl.DoProcess();
				}

				wr1.Close();
				wwl.Close();
		
				wr1 = new WaveReader(stSrcFile1);
				WaveReader wr2 = new WaveReader(stSrcFile2);
				Gain		ga1 = new Gain(0.5f);
				Gain		ga2 = new Gain(0.5f);
				Mixer		mx  = new Mixer(2);
				wwl = new WaveWriter(stDesFile, wr1.NumChannels, wr1.SampleRate, wr1.BitsPerSamples, 1, true);
				ga1.Input = wr1;
				ga2.Input = wr2;
				mx[0] = ga1;
				mx[1] = ga2;
				wwl.Input = mx;
			
				k = 0;
				inter = wr1.Interations;//wwl.Interations;

				for(k = 0; k < inter; k++)
				{
					wr1.DoProcess();
					ga1.DoProcess();
					mx.DoProcess();
					wwl.DoProcess();
				}
				wr1.Close();
				inter = wr2.Interations;

				for(k = 0; k < inter; k++)
				{
					wr2.DoProcess();
					ga2.DoProcess();
					mx.DoProcess();
					wwl.DoProcess();
				}

			
				wr2.Close();
				wwl.Close();
				
			}catch(Exception)
			{
			}
		}
		
		#endregion

		#region  /* Lay thong tin hien thi tren AxWebBrowser */


		static private string GetQuestionText(DataRow row)
		{
			string stFieldTitle = "QuestionText";
			if (row == null)
				return "";
			if (row["SectionID"].ToString() == "1" || row["SectionID"].ToString() == "2")
				stFieldTitle = "Tape";	
			if (row[stFieldTitle] == null)
				return "";
			string stTittle = row[stFieldTitle].ToString();
			int index = stTittle.IndexOf("#"); //se thay bang \r\n
			if(index != -1)
				stTittle = stTittle.Substring(0, index);
			return stTittle;

		}
 #endregion		

		#region /* Xu ly thong tin ve sach : Insert, Update, Delete */

		public static Boolean InsertBook(UCBookInfo uCBook)
		{
			return MyDatabase.InsertBook(uCBook.BookCode, uCBook.BookName, uCBook.Writer);
		}
		public static Boolean UpdateBook(UCBookInfo uCBook)
		{
			return MyDatabase.UpdateBook(uCBook.BookID, uCBook.BookCode, uCBook.BookName, uCBook.Writer);
		}
		public static Boolean LoadBook(int BookID, UCBookInfo uCBook)
		{
			string stBookCode = "", stBookName = "", stWriter = "";
			if(!MyDatabase.LoadBook(BookID, ref stBookCode, ref stBookName, ref stWriter))
				return false;
			uCBook.BookCode = stBookCode;
			uCBook.BookName = stBookName;
			uCBook.Writer   = stWriter;
			return true;
		}
		public static Boolean LoadBooks(ListView lvBooks)
		{
			DataSet ds = new DataSet();
			if(!MyDatabase.LoadBooks(ref ds))
				return false;
			foreach(DataRow row in ds.Tables[0].Rows)
			{
				ListViewItem lvItem = new ListViewItem(row.ItemArray[1].ToString());
				lvItem.Tag = row.ItemArray[0].ToString();
				lvBooks.Items.Add(lvItem);
			}
			return true;
		}

		#endregion

		#region /* Lay thong tin Section */
		public static Boolean LoadSection(int SectionID, UCSectionInfo uCSection)
		{
			string stTittle = "", stDirection = "", stTheEnd = "";
			if(!MyDatabase.LoadSection(SectionID, ref stTittle, ref stDirection, ref stTheEnd))
				return false;
			uCSection.Title = stTittle;
			uCSection.Direction = stDirection;
			uCSection.TheEnd = stTheEnd;
			return true;
		}
		public static Boolean UpdateSection(int SectionID, UCSectionInfo uCSection)
		{
			return MyDatabase.UpdateSection(SectionID, uCSection.Title, uCSection.Direction, uCSection.TheEnd);
		}
		public static Boolean LoadSections(ListView lvSections)
		{
			DataSet ds = new DataSet();
			if(!MyDatabase.LoadSections(ref ds))
				return false;
			foreach(DataRow row in ds.Tables[0].Rows)
			{
				ListViewItem lvItem = new ListViewItem(row.ItemArray[1].ToString());
				lvItem.Tag = row.ItemArray[0].ToString();
				lvSections.Items.Add(lvItem);
			}
			return true;
		}
		#endregion

		#region /* Lay Thong tin ExamTest dua len Properties */
		public static void LoadTestInfo(UCTestInfo uCTest, TreeView trv)
		{
			uCTest.ExamCode = ExamCode;
			uCTest.DateCreate = dtCreate;
			uCTest.LastUpdate = dtLastUpdate;
			/* Dem so luong cau hoi  */
			int nCount = 0;
			int[] arrCount = new int[7];
			for (int i = 0; i< 7 ; i++)
			{
				arrCount[i] = 0;
			}
 			foreach(TreeNode nodeS in trv.Nodes)
			{
				int sID = Convert.ToInt32(nodeS.Tag.ToString().Substring(2));
				if(sID == 4 || sID == 7)
				{
					foreach(TreeNode nodeT in nodeS.Nodes)
					{
						if(nodeT.Tag.ToString().StartsWith("ET"))
						{
							arrCount[sID - 1] += nodeT.Nodes.Count;
							nCount += nodeT.Nodes.Count;
						}
					}
				}
				else
				{
					arrCount[sID - 1] = nodeS.Nodes.Count;
					nCount += nodeS.Nodes.Count;
				}
			
			}
			uCTest.NumofQues = nCount;
			uCTest.NumofPart1 = arrCount[0];
			uCTest.NumofPart2 = arrCount[1];
			uCTest.NumofPart3 = arrCount[2];
			uCTest.NumofPart4 = arrCount[3];
			uCTest.NumofPart5 = arrCount[4];
			uCTest.NumofPart6 = arrCount[5];
			uCTest.NumofPart7 = arrCount[6];
		}
		public static void LoadTestInfo()
		{
			if(TestID > 0)
				MyDatabase.GetExamInfo(TestID, ref dtCreate,ref dtLastUpdate, ref stSchool, ref stClass, ref Duration);
		}
		
		public static void LoadTestInfo(int ExamID, UCTestInfo uCTest)
		{
			DateTime dtCreate = DateTime.Today;
			DateTime dtLastUpdate = DateTime.Today;
			string stExamCode = "";
			int[] arrCount = new int[7];
			MyDatabase.GetExamInfo(ExamID, ref dtCreate, ref dtLastUpdate,ref arrCount, ref stExamCode);
			uCTest.ExamCode = stExamCode;
			uCTest.DateCreate = dtCreate;
			uCTest.LastUpdate = dtLastUpdate;
			int nCount = 0;
			uCTest.NumofPart1 = arrCount[0];
			nCount += arrCount[0];
			uCTest.NumofPart2 = arrCount[1];
			nCount += arrCount[1];
			uCTest.NumofPart3 = arrCount[2];
			nCount += arrCount[2];
			uCTest.NumofPart4 = arrCount[3];
			nCount += arrCount[3];
			uCTest.NumofPart5 = arrCount[4];
			nCount += arrCount[4];
			uCTest.NumofPart6 = arrCount[5];
			nCount += arrCount[5];
			uCTest.NumofPart7 = arrCount[6];
			nCount += arrCount[6];
			uCTest.NumofQues = nCount;
		}
		#endregion

	}
}
